﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <string.h>
int main() {
	char str1[300] = { 0 }, str2[300] = { 0 };
	while (~scanf("%s\n%s", str1, str2)) {
		int n1 = strlen(str1), n2 = strlen(str2);
		int dp[300][300] = { 0 };
		int max[3] = { 0 };
		for (int i = 0; i < n1; i++) {
			for (int j = 0; j < n2; j++) {
				if (str1[i] == str2[j]) {
					if (i == 0 || j == 0) {
						dp[i][j] = 1;
					}
					else {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
					if (max[0] < dp[i][j]) {
						max[0] = dp[i][j];
						max[1] = i;
						max[2] = j;
					}
					else if (max[0] == dp[i][j] && ((n1 < n2 ? max[1] : max[2]) > (n1 < n2 ? i : j))) {
						max[1] = i;
						max[2] = j;
					}
				}
			}
		}

		for (int i = max[1] - max[0] + 1; i <= max[1]; i++) {
			printf("%c", str1[i]);
		}
		printf("\n");
		//for(int i=max[2]-max[0]+1;i<=max[2];i++){ printf("%c",str2[i]);}
	}
}